package chapter_21.generic_interface;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator
 * Created time 2018/8/8 18:41.
 * 自定义的泛型队列集合
 */
public class ListQueue<T> implements IQueue<T> {

    // 声明保存队列元素集合 items
    private List<T> items;

    // 构造方法初始化集合 items
    public ListQueue() {
        items = new ArrayList<>();
    }

    @Override
    public void queue(T item) {
        items.add(item);
    }

    @Override
    public T dequeue() {
        if (items.isEmpty()) {
            return null;
        } else {
            return items.remove(0);
        }
    }

    @Override
    public String toString() {
        return items.toString();
    }
}
